package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.pojo.entity.Device;
import com.example.pojo.entity.Team;
import com.example.service.IDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * TODO
 *
 * @author wy
 * @since 2024/7/17
 */
@RestController
@RequestMapping("/device")
@Api(tags = "设备接口")
public class DeviceController {

    @Autowired
    private IDeviceService iDeviceService;

    /**
     * 分页查询
     */
    @ApiOperation("分页展示设备信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(Device device,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Device> page = iDeviceService.selectPage(device, pageNum, pageSize);
        return Result.success(page);
    }

    @ApiOperation("新增设备信息")
    @PostMapping("/add")
    public Result add(@RequestBody Device device) {
        iDeviceService.add(device);
        return Result.success();
    }

    @ApiOperation("删除设备信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        iDeviceService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("修改设备信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody Device device) {
        iDeviceService.updateById(device);
        return Result.success();
    }
}
